//
//  MeBziQutoeBottomTipe.m
//  ZITHER
//
//  Created by weixin on 2018/11/22.
//  Copyright © 2018 weixn. All rights reserved.
//

#import "MeBziQutoeBottomTipe.h"

@implementation MeBziQutoeBottomTipe


-(void)setModeTyep2:(MyEnquiryListDataEndNewModel *)modeTyep2{
    _modeTyep2 = modeTyep2;
    NSString *str = modeTyep2.acceptPriceCount;
    self.lab2.hidden = YES;

    if ([str isEqualToString:@"0"]) {
        self.hidden = YES;
        [self mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0);
        }];
    }else{
        self.hidden = NO;
        self.lab1.text = [NSString stringWithFormat:@"接受%@个报价",str];
        self.lab1.textAlignment = NSTextAlignmentCenter;
//        [self.btn1 setTitle:[NSString stringWithFormat:@"接受%@个报价",str] forState:UIControlStateNormal];
        [self mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(20);
        }];
        [self.lab1 mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(-5);
            make.left.equalTo(self).offset(20);
            make.width.mas_equalTo(80);
        }];
    }
}

-(NSString*)getCurrentTimes{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    
    // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    
    //现在时间,你可以输出来看下是什么格式
    
    NSDate *datenow = [NSDate date];
    
    //----------将nsdate按formatter格式转成nsstring
    
    NSString *currentTimeString = [formatter stringFromDate:datenow];
    
    NSLog(@"currentTimeString =  %@",currentTimeString);
    
    return currentTimeString;
    
}

-(void)setModeTyep1:(MyEnquiryListDataNewModel *)modeTyep1{
    _modeTyep1 = modeTyep1;
    NSString *str =  [self pleaseInsertStarTimeo:modeTyep1.userEnquiryInfo.refreshTime andInsertEndTime:[self getCurrentTimes]];
    NSInteger index = 0;
    
    if ([str integerValue] < 2) {
        self.lab1.hidden = YES;
        self.lab1.text = @"";

    }else if ([str integerValue]<3.1){
        str = @"  可以刷新询价  ";
        self.lab1.text = str;
        self.lab1.hidden = NO;

        //        [self.btn1 setTitle:str forState:UIControlStateNormal];
        index ++;
    } else{
//        str = [NSString stringWithFormat:@"  询价已%@天未刷新  ",str];
        NSLog(@"pleaseInsertStarTimeo ====  %@",str);
        self.lab1.text = [NSString stringWithFormat:@"  询价已%@天未刷新  ",str];
//        self.lab1.text = @"  询价已@天未刷新  ";

        //        [self.btn1 setTitle:str forState:UIControlStateNormal];
        self.lab1.hidden = NO;
        index ++;
    }
    
    if (![modeTyep1.openSourceCount isEqualToString:@"0"]) {
        self.lab2.text = [NSString stringWithFormat:@"  %@个新公开货源 ",modeTyep1.openSourceCount];

//        [self.btn2 setTitle:[NSString stringWithFormat:@"  %@个新公开货源开  ",modeTyep1.openSourceCount] forState:UIControlStateNormal];
        self.lab2.hidden = NO;

        index ++;
        
        if (index == 1) {
            self.lab1.hidden = YES;
            [self.lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self).offset(0);
            }];
            [self.lab2 mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.lab1.mas_bottom).offset(0);
            }];
        }else{
            self.lab1.hidden = NO;
            [self.lab2 mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.lab1.mas_bottom).offset(10);
            }];
            [self.lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self).offset(10);
            }];
        }
        
    }else{
        self.lab2.hidden = YES;
    }
    
    
  //当前cell总高度
    if (index == 0) {
        
        [self mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0);
        }];
    }else{
        
        [self mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(20+index*20);
        }];
    }
    
//    self.lab1.backgroundColor = [UIColor grayColor];
//    self.lab2.backgroundColor = [UIColor redColor];

    
//
//    if (![modeTyep1.freshPriceCount isEqualToString:@"0"]||![modeTyep1.openSourceCount isEqualToString:@"0"]||![str isEqualToString:@"0"]) {
//        Tips = YES;
//        if (![modeTyep1.freshPriceCount isEqualToString:@"0"]) {
//            [self.labNewReceive setTitle:[NSString stringWithFormat:@"  新收到%@个报价  ",modeTyep1.freshPriceCount] forState:UIControlStateNormal];
//
//        }else{
//            labNewGoodsSources = YES;
//        }
//       else{
//            labNewReceiveType = YES;
//        }
//
//else{
//            labNewRefresh = YES;
//            self.labNewRefresh.enabled = NO;
//        }
//    }
    
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.lab1];
        [self addSubview:self.lab2];
        
        [self.lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(12);
            make.top.equalTo(self).offset(10);
            make.height.mas_equalTo(20);
            make.width.mas_equalTo(110);
        }];
        
        [self.lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(12);
            make.top.equalTo(self.lab1.mas_bottom).offset(10);
            make.height.mas_equalTo(20);
            make.width.mas_equalTo(95);
        }];
    }
    return self;
}

-(BaseLab *)lab1{
    if (!_lab1) {
        _lab1 = [[BaseLab alloc]initializeFrame:CGRectMake(0, 0, 0, 0) text:@"" font:0 textColor:[UIColor colorWithHex:@"7A84ED"] isBold:NO numberOfLines:1];
        _lab1.font = [UIFont fontWithName:@"PingFangSC-Medium" size:12];
        _lab1.backgroundColor = [UIColor colorWithRed:122/255.f green:132/255.f blue:237/255.f alpha:0.08];
    }
    return _lab1;
}

-(BaseLab *)lab2{
    if (!_lab2) {
        _lab2 = [[BaseLab alloc]initializeFrame:CGRectMake(0, 0, 0, 0) text:@"" font:0 textColor:[UIColor colorWithHex:@"7A84ED"] isBold:NO numberOfLines:1];
        _lab2.font = [UIFont fontWithName:@"PingFangSC-Medium" size:12];
        _lab2.backgroundColor = [UIColor colorWithRed:122/255.f green:132/255.f blue:237/255.f alpha:0.08];
    }
    return _lab2;
}

//-(BaseBtn *)btn1
//{
//    if (!_btn1) {
//        _btn1 = [[BaseBtn alloc]initializeFrame:CGRectMake(0, 0, 0, 0) NormalText:@"3个新公开货源" NormalTextColor:[UIColor colorWithHex:@"7A84ED"] SeleText:@"3个新公开货源" SeleTextColor:baseColorTheme font:11 isBold:NO];
//        _btn1.titleLabel.textColor = [UIColor colorWithHex:@"7A84ED"];
//        _btn1.titleLabel.tintColor = [UIColor colorWithHex:@"7A84ED"];
//        [_btn1 setTitleColor:[UIColor colorWithHex:@"#7A84ED"] forState:UIControlStateHighlighted];
//
//        _btn1.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:12];
////        _btn1.backgroundColor = [UIColor RGBColorWithR:244 g:246 b:254];
//        _btn1.backgroundColor = [UIColor whiteColor];
//
//        [_btn1 setCornerRadiusWithRadius:2 isMasks:YES];
//        _btn1.enabled = NO;
//    }
//    return _btn1;
//}
//
//-(BaseBtn *)btn2
//{
//    if (!_btn2) {
////        _btn2 = [[BaseBtn alloc]initializeFrame:CGRectMake(0, 0, 0, 0) NormalText:@"" NormalTextColor:[UIColor colorWithHex:@"7A84ED"] SeleText:@"" SeleTextColor:[UIColor colorWithHex:@"7A84ED"] font:11 isBold:NO];
////
//
//        _btn2 = [BaseBtn buttonWithType:UIButtonTypeCustom];
//        _btn2.frame = CGRectMake(0, 0, 1, 1);
//        [_btn2 setTitleColor:[UIColor colorWithHex:@"#7A84ED"] forState:UIControlStateNormal];
//        [_btn2 setTitleColor:[UIColor colorWithHex:@"#7A84ED"] forState:UIControlStateDisabled];
//
////        _btn2.titleLabel.textColor = [UIColor colorWithHex:@"7A84ED"];
//        _btn2.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:12];
////        _btn2.backgroundColor = [UIColor RGBColorWithR:244 g:246 b:254];
//        _btn2.backgroundColor = [UIColor whiteColor];
//
//        [_btn2 setCornerRadiusWithRadius:2 isMasks:YES];
////        _btn2.enabled = NO;
//    }
//    return _btn2;
//}

- (NSString *)pleaseInsertStarTimeo:(NSString *)time1 andInsertEndTime:(NSString *)time2{
    // 1.将时间转换为date
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSDate *date1 = [formatter dateFromString:time1];
    NSDate *date2 = [formatter dateFromString:time2];
    // 2.创建日历
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSCalendarUnit type = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    // 3.利用日历对象比较两个时间的差值
    NSDateComponents *cmps = [calendar components:type fromDate:date1 toDate:date2 options:0];
    // 4.输出结果
    
    NSLog(@"%@",[NSString stringWithFormat:@"%ld",cmps.day]);
    return [NSString stringWithFormat:@"%ld",cmps.day];
}
@end
